package com.situ.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.situ.domain.dto.OrderReportDTO;
import com.situ.domain.entity.TOrderItem;
import com.situ.domain.vo.BussinessReportVO;
import com.situ.mapper.TOrderItemMapper;
import com.situ.service.OrderItemService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class OrderItemServiceImpl extends ServiceImpl<TOrderItemMapper, TOrderItem> implements OrderItemService {


    private final TOrderItemMapper orderItemMapper;

    /**
     * 获取业务报表
     *
     * @return
     */
    @Override
    public List<BussinessReportVO.HotProduct> getBussinessHotProduct() {
        List<OrderReportDTO> orderReport = orderItemMapper.getBusinessOrderReport();
        // 获取总购买量:
        Long totalNums = orderItemMapper.getTotalnums();
        List<BussinessReportVO.HotProduct> list = orderReport
                .stream()
                .map(item -> {
                    BussinessReportVO.HotProduct hotProduct = new BussinessReportVO.HotProduct();
                    hotProduct.setTitle(item.getTitle());
                    hotProduct.setTotalNum(item.getTotalNum());
                    hotProduct.setPresent(item.getTotalNum() * 1.0 / totalNums * 100);
                    hotProduct.setSellPoint(item.getSellPoint());
                    return hotProduct;
                }).toList();
        return list;
    }
}
